package br.edu.utfpr.md.tads.controller.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import br.edu.utfpr.md.tads.R;
import br.edu.utfpr.md.tads.model.Contato;

public class ContatoListAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private List<Contato> contatos;
	
	
	public ContatoListAdapter(Context  context, List<Contato> contatos) {
		this.inflater = LayoutInflater.from(context);
		this.contatos = contatos;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return contatos.size();
	}

	@Override
	public Object getItem(int postion) {
		// TODO Auto-generated method stub
		return contatos.get(postion);
	}

	@Override
	public long getItemId(int postion) {
		// TODO Auto-generated method stub
		return Long.parseLong(contatos.get(postion).getId());
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		
		Contato contato = contatos.get(position);
		view = inflater.inflate(R.layout.layout_item_list_contato, null);
		
		TextView textViewNome = (TextView) view.findViewById(R.layout_item_listcontato.text_view_nome);
		TextView textViewEndereco = (TextView) view.findViewById(R.layout_item_listcontato.text_view_endereco);
		TextView textViewTelefone = (TextView) view.findViewById(R.layout_item_listcontato.text_view_telefone);
		
		textViewNome.setText(contato.getNomeCompreto());
		textViewEndereco.setText(contato.getEnderecoCompleto());
		textViewTelefone.setText(contato.getTelefones().get(0));
		return view;
	}



}
